public class CommonDivisor {
    public static void main(String[]args){
        java.util.Scanner in = new java.util.Scanner(System.in);
        String info="最大公约数";
        System.out.println("请输入两个数 来求取这两个数的"+info);
        System.out.print("第一个数:");
        int a=in.nextInt();
        System.out.print("第二个数:");
        int b=in.nextInt();
        System.out.println(""+a+" 和 "+b+" 的"+info+" 是 "+CommonDivisor(a,b));
    }
    public static int CommonDivisor(int fir,int sec){
    return new TwoInt(fir,sec).O();
    }
}
class TwoInt{
    public int f,b;
    public TwoInt(int x,int y){
        this.f=x;
        this.b=y;
    }
    public void swap(){
        if(reverse()){
            int temp=f;
            this.f=this.b;
            this.b=temp;
        }
    }
    public boolean reverse(){
        return f<b;
    }
    public void set(int a,int b){
        this.f=a;
        this.b=b;
    }
    public int O(){
        int rel=1;
        swap();
        while(rel!=0){
            rel=f%b;
            set(b,rel);
            swap();
        }
        return f;
    }
}